package com.zisuyi.game.sdk.game

import android.os.VibrationEffect
import android.os.Vibrator
import androidx.core.content.getSystemService
import com.weilele.mvvm.app

class VibratorHelper {
    companion object {
        private val vibrator by lazy { app.getSystemService<Vibrator>() }
        private const val VIBRATOR_TIME = 200L
    }

    /**
     * 震动手机
     */
    fun vibrator() {
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
            vibrator?.vibrate(
                VibrationEffect.createOneShot(
                    VIBRATOR_TIME,
                    VibrationEffect.DEFAULT_AMPLITUDE
                )
            )
        } else {
            vibrator?.vibrate(VIBRATOR_TIME)
        }
    }
}